<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<title>simExecuteScriptString</title>
<link rel="stylesheet" type="text/css" href="../../style.css">
</head>

<body>

<div align="center">
<table class=allEncompassingTable >
 <tr>
  <td >
<p><a href="../../index.html" TARGET="_top"><img src="../images/homeImg.png"></a></p>

<h1><a href="../apiOverview.htm">Regular API</a> function</h1>
<h3 class=subsectionBar><a name="simExecuteScriptString" id="simExecuteScriptString"></a>simExecuteScriptString / sim.executeScriptString</h3>
<table class=apiTable>
<tr class=apiTableTr> 
<td class=apiTableLeftDescr>
Description 
</td> 
<td class=apiTableRightDescr>Executes some Lua code in a specific script (from a <a href="../plugins.htm">plugin</a>, <a href="../mainClientApplication.htm">the main client application</a>, or from another script). Call this only:<br>
a) from the main thread, or:<br>
b) from a thread that originated from a threaded child script. In that case, you cannot call non-threaded child scripts.<br>
When calling <a href="../simulationScripts.htm">simulation scripts</a>, then simulation must be running. See also <a href="simCallScriptFunction.htm">sim.callScriptFunction</a>. <br><br>
<div>Data exchange between a plugin and a script happens via a <a href="../apiFunctionListCategory.htm#stacks">stack</a>. Reading and writing arguments from/to the stack gives you a maximum of flexibility, and you wil be able to exchange also complex data structures. But it can also be tedious and error prone. Use instead the helper classes located in <em>programming/common/stack</em> and <em>programming/include/stack</em>: they will greatly simplify the task. Have a look at the example plugins <a href="https://github.com/CoppeliaRobotics/simExtPluginSkeleton" target="_blank">simExtPluginSkeleton</a> and <a href="https://github.com/CoppeliaRobotics/simExtPluginSkeletonNG" target="_blank">simExtPluginSkeletonNG</a>.</div>


</td>
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftCSyn>
C synopsis
</td> 
<td class=apiTableRightCSyn>simInt simExecuteScriptString(simInt scriptHandleOrType,const simChar* stringAtScriptName,simInt stackId)</td> 
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftCParam>C parameters</td> 
<td class=apiTableRightCParam>
<div><strong>scriptHandleOrType</strong>: the handle of the script, otherwise the type of the script:</div>
<div class=tab><em>sim_scripttype_mainscript</em> (0): the <a href="../mainScript.htm">main script</a>.</div>
<div class=tab><em>sim_scripttype_childscript</em> (1): a <a href="../childScripts.htm">child script</a>. In that case, <em>stringAtScriptName</em> should also contain the name of the object associated with the script.</div>
<div class=tab><em>sim_scripttype_customizationscript</em> (6): a <a href="../customizationScripts.htm">customization script</a>. In that case, <em>stringAtScriptName</em> should also contain the name of the object associated with the script.</div>
<div class=tab><em>sim_scripttype_sandboxscript</em> (8): <a href="../sandboxScript.htm">the sandbox script</a>.</div>
<div><strong>stringAtScriptName</strong>: some Lua code to execute in the specified script, followed by @: &quot;string@&quot;. If <em>scriptHandleOrType</em> is <em>sim_scripttype_childscript</em>, or <em>sim_scripttype_customizationscript</em>, then <em>stringAtScriptName</em> should also contain the name of the object associated with the script: &quot;string@objectName&quot;.</div>
<div><strong>stackId</strong>: 0 (for no stack) or a <a href="simCreateStack.htm">stack handle</a>. The stack holds possible out values. See also the <a href="../apiFunctionListCategory.htm#stacks">available stack functions</a>.</div>
</td> 
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftCRet>
C return value
</td> 
<td class=apiTableRightCRet>
<div>-1 in case of an error</div>
</td> 
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftLSyn>
Lua synopsis
</td> 
<td class=apiTableRightLSyn>number result,executionResult=sim.executeScriptString(string stringAtScriptName,number scriptHandleOrType)</td> 
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftLParam>Lua parameters</td> 
<td class=apiTableRightLParam>
<div>Similar to the C-function counterpart</div>
</td> 
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftLRet>
Lua return values
</td> 
<td class=apiTableRightLRet>
<div><strong>result</strong>: -1 in case of an error</div>
<div><strong>executionResult</strong>: return value of the executed code</div>
</td> 
</tr> 

<tr class=apiTableTr> 
<td class=remApiTableLeftCParam>
Remote API equiv.
</td> 
<td class=remApiTableRightCParam>
<div>B0-based remote API: <a href="../b0RemoteApi-cpp.htm#simxExecuteScriptString">simxExecuteScriptString</a></div>
<div>Legacy remote API: -</div>
</td> 
</tr> 

</table> 

<br>
<p><a href="../apiFunctions.htm">All regular API functions on one page</a></p>
<br>
<br>
</td>
</tr>
</table>
</div>
</body>
</html>
